﻿<%@ Import namespace="TTQT.TTQT_Code.Info"%>
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="HorizontalMenu2.ascx.cs" Inherits="UserControl_HorizontalMenu2" %>
<script runat="server">
	public void addMenuCon(string menuName,int menuId)
	{
	    Response.Write("<li><a href=\"Default.aspx?pageId=" + menuId+ "\">"+menuName+"</a></li>");
	}
    public void addMenuCha(string menuName, int menuId, bool disable)
    {
        if(disable)
        {
            Response.Write("<a href=\"#\">" + menuName + "</a>");
        }else{
            Response.Write("<a href=\"Default.aspx?pageId=" + menuId + "\">" + menuName + "</a>");
        }
    }
</script>
<div id="nav" style="text-align:left;">
    <ul class="clearfix">
        <%
            try
            {
                if (Session["UserId"] != null)
                {
                    UserInfo userInfo = TTQT.TTQT_Code.DataAccessObject.instance().getUser(TTQT.TTQT_Code.TTQTCommon.ToInt32(Session["UserId"].ToString(), -1));
                    ArrayList listCmd;
                    if (userInfo.isSuperAdmin.Equals("1"))
                    {
                        listCmd = TTQT.TTQT_Code.DataAccessObject.instance().getAllMenu();
                    }
                    else
                    {
                        listCmd = TTQT.TTQT_Code.DataAccessObject.instance().GetArrayCmdsByUser_Id(userInfo.userId);
                    }
                    if (listCmd.Count < 1)
                    {
                        Response.Write("<center>&nbsp;<span style='color:yellow;font-weight:bold;'>NGƯỜI DÙNG NÀY CHƯA ĐƯỢC PHÂN QUYỀN. VUI LÒNG LIÊN HỆ VỚI NGƯỜI QUẢN TRỊ TRỰC TIẾP!</span></center>");
                        return;
                    }
                    bool truocDoLaCha=false,truocDoLaCon=false;
                    for (int i = 0; i < listCmd.Count; i++)
                    {
                        CmdInfo cmd = (CmdInfo)listCmd[i];
                        //Hien tai la cha
                        if (cmd.Cmd_Parent_Id == 0)
                        {
                            if(!truocDoLaCha &!truocDoLaCon)
                            {
                                Response.Write("<li>");
                                if(cmd.Cmd_Path.Equals(""))
                                {
                                    addMenuCha(cmd.Cmd_Name, cmd.Cmd_Id,true);
                                }
                                else
                                {
                                    addMenuCha(cmd.Cmd_Name, cmd.Cmd_Id, true);
                                }
                            }
                            if (!truocDoLaCha && truocDoLaCon)
                            {
                                Response.Write("</ul></li><li>");
                                if (cmd.Cmd_Path.Equals(""))
                                {
                                    addMenuCha(cmd.Cmd_Name, cmd.Cmd_Id, true);
                                }
                                else
                                {
                                    addMenuCha(cmd.Cmd_Name, cmd.Cmd_Id, true);
                                }
                            }
                            if(truocDoLaCha)
                            {
                                Response.Write("</li><li>");
                                if (cmd.Cmd_Path.Equals(""))
                                {
                                    addMenuCha(cmd.Cmd_Name, cmd.Cmd_Id, true);
                                }
                                else
                                {
                                    addMenuCha(cmd.Cmd_Name, cmd.Cmd_Id, true);
                                }
                            }
                            truocDoLaCha = true;
                            truocDoLaCon=false;
                        }
                        else // Hiện tại là con
                        {
                            if(truocDoLaCha)
                            {
                                Response.Write("<ul>");
                                addMenuCon(cmd.Cmd_Name, cmd.Cmd_Id);
                            }
                            if(truocDoLaCon)
                            {
                                addMenuCon(cmd.Cmd_Name, cmd.Cmd_Id);
                            }
                            truocDoLaCon=true;
                            truocDoLaCha=false;
                        }
                    }
                    if(truocDoLaCha)
                    {
                        Response.Write("</li>");
                    }
                    if(truocDoLaCon)
                    {
                        Response.Write("</ul></li>");
                    }
                }
            }
            catch (Exception ex)
            {
                //string err=ex.ToString();
                //Response.Write(err);
            }
            
        
        %>
   </ul>
</div>

<!--
<div id="Div1">
    <ul class="clearfix">
    
        <li>
            <a>bebebebebebbebe</a>
        </li>
        
        <li>
            <a>bebebebebebbebe</a>
            <ul>
                <li><a href="#">me nu con 1</a></li>
                <li><a>me nu con 2</a></li>
                <li><a>me nu con 3</a></li>
            </ul>
        </li>    
        
        <li>
            <a>bebebebebebbebe</a>
        </li>    
        
        <li>
            <a>bebebebebebbebe</a>
            <ul>
                <li><a href="#">me nu con 1</a></li>
                <li><a>me nu con 2</a></li>
                <li><a>me nu con 3</a></li>
            </ul>
        </li>
    </ul>
</div>
-->